package com.atwei.mango.mybatis.config;

import com.atwei.mango.mybatis.DataScopeStatementHandler;
import com.atwei.mango.mybatis.SaveUpdateHandler;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * MybatisPlus,mybatis配置
 * @author liuwei
 * @date 2021/10/22 15:02
 */
@Configuration
public class MybatisPlusConfig {
    /**
     *分页插件Bean
     * @return com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor
     * @throws
     * @author liuwei
     * @date 2021/10/22 15:09
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        //添加分页插件
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        //添加乐观锁插件
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        return interceptor;
    }

    /**
     * @Description 自定义权限插件
     * @Author liuwei
     * @Date 2022/5/12 9:43
     * @params []
     * @return com.atwei.mango.mybatisPlugins.DataScopeStatementHandler
     **/
    @Bean
    public DataScopeStatementHandler dataScopeStatementHandler(){
        return new DataScopeStatementHandler();
    }
    /**
     * @Description mybatisplus自动填充策略
     * @Author liuwei
     * @Date 2022/5/13 11:31
     * @params []
     * @return com.atwei.mango.mybatisPlugins.SorUMetaObjectHandler
     **/
    @Bean
    public SaveUpdateHandler sorUMetaObjectHandler(){
        return new SaveUpdateHandler();
    }

}
